<?php
namespace app\move\logic;


use app\common\helper\StatusCode;
use app\common\model\Consult;
use app\common\model\ConsultBanner;
use app\common\model\ConsultItem;
use app\common\model\Lists;
use think\Db;

Class ArticleLogic extends BaseLogic
{
    public function banner()
    {
        $r = ConsultBanner::where('state',StatusCode::DEFAULT_ONE)->select();

        return $r;
    }

    public function listing($page_size=10)
    {
        $where = [];

        $r = Consult::where($where)->field(true)->limit($this->getPagingParams())->order(['sort' => 'desc', 'create_time' => 'desc'])->select()->toArray();

        foreach ($r as &$val) {
            $val['source'] = ConsultItem::where('consult_id', $val['id'])->value('source');
            $val['content'] = ConsultItem::where('consult_id', $val['id'])->value('content');
        }

        return $r;
    }

    public function info($id)
    {
        // 资讯详情
        $info = Db::table('consult')->alias('c')->join('consult_item','c.id=consult_item.consult_id')->where(['c.id'=>$id])->find();
        // 优惠资讯
        $consult = Consult::order('view','desc')->limit(6)->select();
        // 推荐车型
        $list = Lists::field('z_img,title,id')->limit(5)->select();
        return compact('info','consult','list');
    }
}